<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<form:form commandName="datebean" cssClass="form-horizontal" role="form">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">基本信息</h3>
        </div>
        <div class="panel-body">
            <div class="col-sm-12">
                <div class="form-group">

                    <label class="col-sm-2 control-label no-padding-right" for="name">姓名<font
                            color="red">*</font></label>
                    <div class="col-sm-3">
                        <input type="text" name="name" id="name" placeholder="请输入姓名" value="${datebean.name}"
                               class="form-control required">
                    </div>

                    <label class="col-sm-2 control-label no-padding-right" for="username">用户名<font color="red">*</font></label>
                    <div class="col-sm-3">
                        <input type="text" name="username" id="username" placeholder="请输入用户名"
                               value="${datebean.username}" class="form-control required">
                    </div>
                </div>


                <div class="form-group">

                </div>

                <div class="form-group">

                    <label class="col-sm-2 control-label no-padding-right" for="password">密码<font
                            color="red">*</font></label>
                    <div class="col-sm-3">
                        <input type="password" name="password" id="password" placeholder="请输入密码"
                               value="${datebean.password}" class="form-control required">
                    </div>

                    <label class="col-sm-2 control-label no-padding-right" for="mobile">手机号码</label>
                    <div class="col-sm-3">
                        <input type="text" name="mobile" id="mobile" placeholder="请输入手机号码" value="${datebean.mobile}"
                               class="form-control required ">
                    </div>
                </div>

                <div class="form-group">


                </div>

                <c:if test="${datebean.demo != '1'}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right" for="roleId">角色</label>
                        <div class="col-sm-3">
                                <%--<form:select path="roleId" items="${redis:getDictList('Position',false)}" itemValue="basId" itemLabel="name" cssClass="form-control"></form:select>--%>
                            <input type="hidden" class="datebeanRoleId" value="${datebean.roleId}">
                            <select name="roleId" id="roleId" class="form-control">
                                    <%--<option value="${datebean.roleId}">${datebean.roleId}</option>--%>
                                    <%--<c:forEach items="${redis:getDictList('Position',false)}" var="position">
                                        <c:if test ="${position.basId!='01'&&position.basId!='10'&&position.basId!='20'}">
                                            <option value="${position.basId}">${position.name}</option>
                                        </c:if>
                                    </c:forEach>--%>
                                <c:if test="${datebean.roleId==null}">
                                    <option value="02">主要领导</option>
                                    <option value="03">分管领导</option>
                                    <option value="04">经办人</option>
                                </c:if>

                                <c:if test="${datebean.roleId=='02'}">

                                    <option value="02" selected>主要领导</option>
                                    <option value="03">分管领导</option>
                                    <option value="04">经办人</option>
                                </c:if><c:if test="${datebean.roleId=='03'}">

                                <option value="02">主要领导</option>
                                <option value="03" selected>分管领导</option>
                                <option value="04">经办人</option>

                            </c:if><c:if test="${datebean.roleId=='04'}">
                                <option value="02">主要领导</option>
                                <option value="03">分管领导</option>
                                <option value="04" selected>经办人</option>
                            </c:if>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label no-padding-right" for="position">职务</label>
                        <div class="col-sm-3">
                            <input type="text" name="position" id="position" placeholder="请输入职务"
                                   value="${datebean.position}" class="form-control ">
                        </div>
                    </div>
                </c:if>

                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="roleId">选择科室</label>
                    <div class="col-sm-3">
                        <select style="width:100%"  name="roomId" id="theroomName" class="form-control">
                            <option value="">请选择</option>
                        </select>
                    </div>
                    <div class="col-sm-7"></div>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" name="floorId" value="${datebean.floorId}">
    <input type="hidden" name="userId" id="thisuser2Id"  value="${datebean.userId}">
    <input type="hidden" name="deptId" id="thisuserId" value="${datebean.deptId}">
</form:form>
<script>
    $(function () {
        var $datebeanRoleId = $(".datebeanRoleId").val();   //获取input中输入的数字
        var $roleIds = $("#roleId").find("option"); //获取select下拉框的所有值
        for (var j = 1; j < $roleIds.length; j++) {
            if ($($roleIds[j]).val() == $datebeanRoleId) {
                $($roleIds[j]).attr("selected", "selected");
            }
        }
    })


      setTimeout(function(){
          $.ajax({
          type: "GET",
          url: "/sys/deptRoom/getrooms?deptId="+ $("#thisuserId").val(),
          contentType: 'application/json;charset=utf-8', //设置请求头信息
          // data: "devId=" + devId, //必须是字符串
          dataType: "json",
          success: function (data) {
              console.log(data)
              for(let i=0;i<data.data.length;i++){
                  var option  = document.createElement("option")
                  option.value = data.data[i].sysId
                  option.text = data.data[i].roomName
                  var theroomName = document.querySelector("#theroomName")
                  theroomName.add(option)
                  <%--$("#theroomName").append(`<option style="color:black;" value="${data.data[i].sysId}">${data.data[i].roomName}</option>`)--%>
              }
          }
      });
      },3000)

</script>